package com.kmxd.ams.controller.archive;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kmxd.ams.client.archive.IArchiveRuleCatalogSvc;
import com.kmxd.ams.client.archive.dto.ArchiveRuleCatalogAddDTO;
import com.kmxd.ams.client.archive.dto.ArchiveRuleCatalogEditDTO;
import com.kmxd.ams.client.archive.dto.ArchiveRuleCatalogQueryDTO;
import com.kmxd.ams.client.archive.vo.ArchiveRuleCatalogListVO;
import com.kmxd.ams.client.archive.vo.ArchiveRuleCatalogVO;
import com.kmxd.ams.core.log.annotation.AutoLog;
import com.kmxd.ams.core.result.R;
import com.kmxd.ams.core.util.SecurityUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 整理规则-目录树设置 前端控制器
 *
 * @author nickbi
 * @since 2023-08-09
 */
@RestController
@Tag(name = "整理规则-目录树设置")
@RequestMapping("/archive/archiveRuleCatalog")
@AllArgsConstructor
public class ArchiveRuleCatalogCtl {

  private IArchiveRuleCatalogSvc archiveRuleCatalogService;

  /** 分页查询 */
  @Operation(summary = "分页查询")
  @RequestMapping("/selectPage")
  @AutoLog(module = "整理规则-目录树设置", title = "分页查询")
  public R<Page<ArchiveRuleCatalogListVO>> selectPage(
      Page reqPage, ArchiveRuleCatalogQueryDTO req) {
    req.setComId(SecurityUtil.getCropId());
    req.setFondsId(SecurityUtil.getFondsId());
    return R.success(archiveRuleCatalogService.selectPage(reqPage, req));
  }

  /** 列表查询 */
  @Operation(summary = "列表查询")
  @RequestMapping("/selectList")
  @AutoLog(module = "整理规则-目录树设置", title = "列表查询")
  public R<List<ArchiveRuleCatalogListVO>> selectList(ArchiveRuleCatalogQueryDTO req) {
    req.setComId(SecurityUtil.getCropId());
    req.setFondsId(SecurityUtil.getFondsId());
    return R.success(archiveRuleCatalogService.selectList(req));
  }

  /** 新增 */
  @Operation(summary = "新增")
  @PostMapping("/add")
  @SaCheckPermission("archive:archiveRuleCatalog:add")
  @AutoLog(module = "整理规则-目录树设置", title = "新增")
  public R<Void> add(@Validated @RequestBody ArchiveRuleCatalogAddDTO req) {
    req.setComId(SecurityUtil.getCropId());
    req.setFondsId(SecurityUtil.getFondsId());
    archiveRuleCatalogService.add(req);
    return R.success();
  }

  /** 修改 */
  @Operation(summary = "修改")
  @PostMapping("/edit")
  @SaCheckPermission("archive:archiveRuleCatalog:edit")
  @AutoLog(module = "整理规则-目录树设置", title = "修改")
  public R<Void> edit(@Validated @RequestBody ArchiveRuleCatalogEditDTO req) {
    archiveRuleCatalogService.edit(req);
    return R.success();
  }

  /** 删除 */
  @Operation(summary = "删除")
  @PostMapping("/remove")
  @SaCheckPermission("archive:archiveRuleCatalog:remove")
  @AutoLog(module = "整理规则-目录树设置", title = "删除")
  public R<Void> remove(@RequestParam String ids) {
    archiveRuleCatalogService.remove(ids);
    return R.success();
  }

  /** 查看 */
  @Operation(summary = "查看")
  @GetMapping("/view")
  @AutoLog(module = "整理规则-目录树设置", title = "查看")
  public R<ArchiveRuleCatalogVO> view(@RequestParam Long id) {
    return R.success(archiveRuleCatalogService.view(id));
  }

  @Operation(summary = "查看自定义标识")
  @GetMapping("/customFlag")
  @AutoLog(module = "整理规则-目录树设置", title = "查看自定义标识")
  public R<Boolean> getCustomFlag(Integer status) {
    return R.success(
        archiveRuleCatalogService.getCustomFlag(
            SecurityUtil.getCropId(), SecurityUtil.getFondsId(), status));
  }

  @Operation(summary = "修改自定义标识")
  @PostMapping("/changeFlag")
  @AutoLog(module = "整理规则-目录树设置", title = "修改自定义标识")
  public R<Void> changeFlag(
      @RequestParam("flag") Boolean flag, @RequestParam("status") Integer status) {
    archiveRuleCatalogService.changeCustomFlag(
        SecurityUtil.getCropId(), SecurityUtil.getFondsId(), status, flag);
    return R.success();
  }

  @Operation(summary = "排序")
  @PostMapping("/changeSort")
  @AutoLog(module = "整理规则-目录树设置", title = "排序")
  public R<Void> changeSort(@RequestParam String ids) {
    archiveRuleCatalogService.changeSort(ids);
    return R.success();
  }
}
